<style>
    .layui-form-item .layui-input-inline {
    float: left;
    width: 131px;
    margin-right: 10px;
}
</style>

<div class="layuimini-container layui-anim layui-anim-upbit">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" id="form">
                    <div class="layui-form-item">
                        <!-- <div class="layui-inline">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="jobNumberSearch" autocomplete="off" class="layui-input"
                                    id="jobNumber">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="userNameSearch" autocomplete="off" class="layui-input"
                                    id="userName">
                            </div>
                        </div> -->

                        <div class="layui-inline">
                            <label class="layui-form-label">分组方式</label>
                            <div class="layui-input-inline">
                                <select name="groupType" lay-filter="clsSelects">
                                    <option value='nochoice'>不分组</option>
                                    <option value="user_name">按用户名分组</option>
                                    <option value="resource_name">按数据源分组</option>
                                    <option value="resource_title">按标题分组</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline" id="word" style="left: 20px">
                            <label class="layui-form-label" id="userIdChoice">用户ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="groupValue" placeholder="请输入用户ID" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline" style="left: 44px;">
<!--                            <label class="layui-form-label" hidden>访问类型</label>-->

                            <div class="layui-input-inline" >
                                <div style="display:none;" hidden >
                                <select name="accessType" lay-filter="clsSelects" style="display: none">
<!--                                    <option value="">全部</option>-->
                                    <option selected="selected" value='浏览' style="display: none">浏览</option>
<!--                                    <option value='下载'>下载</option>-->
<!--                                    <option value='检索'>检索</option>-->
                                </select>
                                </div>
                            </div>
                        </div>
                        <!--<div class="layui-inline">-->
                            <!--<label class="layui-form-label">资源来源</label>-->
                            <!--<div class="layui-input-inline">-->
                                <!--<select name="source" lay-filter="clsSelects">-->
                                    <!--<option value="">全部</option>-->
                                    <!--<option value='2_情报资源'>情报资源</option>-->
                                    <!--<option value='4_情报自用'>情报自用</option>-->
                                    <!--<option value='3_研究成果'>研究成果</option>-->
                                <!--</select>-->
                            <!--</div>-->
                        <!--</div>-->

                        <div class="layui-inline" style="left: -100px">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                lay-filter="data-search-btn"
                                style="width:90px;height:38px;border:none;outline:none;position: relative;top:17px; left: 200px;
                                background-color:#007bff;color:white":><i
                                    class="layui-icon"></i> 搜 索</button>

                            <button type="submit" lay-submit="" class="layui-btn layui-btn-warm"
                                lay-filter="data-export-btn"
                                style="width:90px;background-color:#26B99A;;position: relative;top:17px; left: 200px">
                                <i class="layui-icon"></i> 导 出</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <br>
        <div id="table" lay-filter="currentTableFilter">

        </div>
        <div id="page"></div>
    </div>
</div>





<script>
    layui.form.render();
    var tableBar = [
        { title: '序 号', type: 'numbers', width: '10%', align: "center" },
        { field: 'user_id', title: '用 户 ID',  width: '8%', align: "center" },
        { field: 'user_name', title: '姓 名',  width: '10%', align: "center" },
        { field: 'resource_title', title: '标 题',  width: '32%', align: "center" },
        { field: 'resource_name', title: '数 据 来 源',  width: '10%', align: "center" },
        { field: 'create_time', title: '访 问 时 间',  width: '20%', align: "center" },
    ]
    var tableBar2 = [
        { title: '序 号', type: 'numbers',  width: '20%', align: "center" },
        { field: 'user_name', title: '姓名',  width: '20%', align: "center" },
        { field: 'user_id', title: '用 户 ID',  width: '20%', align: "center" },
        { field: 'countnumber', title: '合 计',  width: '40%', align: "center" }
    ]

    var tableBar3 = [
        { title: '序 号', type: 'numbers',  width: '20%', align: "center" },
        { field: 'resource_name', title: '数 据 来 源',  width:'20%', align: "center" },
        { field: 'user_id', title: '用 户 ID',  width: '20%', align: "center" },
        { field: 'countnumber', title: '合 计',  width: '40%', align: "center" }
    ]
    var tableBar4 = [
        { title: '序 号', type: 'numbers',  width: '20%', align: "center" },
        { field: 'resource_title', title: '标 题',  width:'40%', align: "center" },
        { field: 'user_id', title: '用 户 ID',  width: '20%', align: "center" },
        { field: 'countnumber', title: '合 计',  width: '20%', align: "center" }
    ]

    var initTableParams = {
        "groupType": "",
        "groupValue": "",
        "accessType": "浏览",
        "source": "",
        "orderType": "创建时间",
        "orderValue": "desc",
        "page": 1,
        "pageSize": 10
    }


    //封装 表格渲染方法
    function tableRender(tableBar, initTableParams) {
        layuiEx.tableRender(
            "/ViewLog/getViewLog",
            'table',
            'page',
            tableBar,
            initTableParams
        );
    }

    tableRender(tableBar, initTableParams)

    //检索事件
    layui.form.on('submit(data-search-btn)', function (params) {
        console.log("**************************")
        console.log(params.field.groupType)
        if (params.field.groupType == "user_name") {
            layuiEx.tableRender(
                "/ViewLog/getViewLog",
                'table',
                'page',
                tableBar2,
                {
                    "groupType": params.field.groupType,
                    "groupValue": params.field.groupValue,
                    "accessType": params.field.accessType,
                    "source": params.field.source,
                    "orderType": "count(*)",
                    "orderValue": "desc",
                    "page": 1,
                    "pageSize": 10
                }
            );
            return false
        }
        else if (params.field.groupType == "resource_name") {
            layuiEx.tableRender(
                "/ViewLog/getViewLog",
                'table',
                'page',
                tableBar3,
                {
                    "groupType": params.field.groupType,
                    "groupValue": params.field.groupValue,
                    "accessType": params.field.accessType,
                    "source": params.field.source,
                    "orderType": "count(*)",
                    "orderValue": "desc",
                    "page": 1,
                    "pageSize": 10
                }
            );
            return false
        }
        else if (params.field.groupType == "resource_title") {
            layuiEx.tableRender(
                "/ViewLog/getDownLog",
                'table',
                'page',
                tableBar4,
                {
                    "groupType": params.field.groupType,
                    "groupValue": params.field.groupValue,
                    "accessType": params.field.accessType,
                    "source": params.field.source,
                    "orderType": "count(*)",
                    "orderValue": "desc",
                    "page": 1,
                    "pageSize": 10
                }
            );
            return false
        }

        else {
            layuiEx.tableRender(
                "/ViewLog/getViewLog",
                'table',
                'page',
                tableBar,
                {
                    "groupType": params.field.groupType,
                    "groupValue": params.field.groupValue,
                    "accessType": params.field.accessType,
                    "source": params.field.source,
                    "orderType": "创建时间",
                    "orderValue": "desc",
                    "page": 1,
                    "pageSize": 10
                }
            );
            return false
        }
    })

    //监听导出按钮
    layui.form.on('submit(data-export-btn)', function (data) {
        var groupType = data.field.groupType
        var groupValue = data.field.groupValue
        var source = data.field.source
        var accessType = data.field.accessType
        var orderType = "count(*)"
        var orderValue = "desc"
        var url = config.server + "/adminLog/exportViewDownloadLog?source=" + source + "&accessType=" + accessType + "&orderType=" + orderType + "&orderValue=" + orderValue + "&groupType=" + groupType + "&groupValue=" + groupValue
        window.location.href = url;
        return false;
    });

</script>